import request from '../utils/request';
import {baseServerUrl} from "../utils/Constant";
import {stringify} from "qs";

export async function query() {
  return request('/api/users');
}

export async function queryCurrent() {
  return request(`${baseServerUrl}/tms/tms-user/current`);
}

export async function userPage(params) {
  return request(baseServerUrl + `/user/sys-user/page?${stringify(params)}`,{
    method: 'GET'
  });
}

export async function userInsert(params) {
  return request(`${baseServerUrl}/user/sys-user`, {
    method: 'POST',
    body: {
      ...params,
    }
  })
}

export async function userDel(params) {
  return request(`${baseServerUrl}/user/sys-user`, {
    method: 'DELETE',
    body: {
      ...params,
    }
  })
}

export async function userEdit(params) {
  return request(`${baseServerUrl}/user/sys-user`, {
    method: 'PUT',
    body: {
      ...params,
    }
  })
}

export async function rolesData(params) {
  return request(`${baseServerUrl}/user/sys-user-role/transfer?${stringify(params)}`, {
    method: 'GET'
  })
}

export async function saveUserRoles(params) {
  let body = new FormData();
  Object.keys(params).map(key => {
    body.append(key,params[key]);
  })
  return request(`${baseServerUrl}/user/sys-user-role/save`, {
    method: 'POST',
    body: body
  })
}
